﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace NH.Core.Model
{
    public class Category : BaseEntity
    {


        public virtual string Name { get; set; }

        public virtual ICollection<Product> Products { get; protected set; }

        public Category()
        {
            Products = new Collection<Product>();
        }

        public virtual void AddProduct(Product product)
        {
            Check.Require<ArgumentNullException>(product != null, "Product is null");
            Check.Require<ArgumentException>(!Products.Contains(product), "Already exist");

            Products.Add(product);
        }

        public virtual void RemoveProduct(Product product)
        {
            Check.Require<ArgumentException>(product != null, "Product");
            Check.Require<ArgumentException>(Products.Contains(product), "Exist");

            Products.Remove(product);
        }

        public override bool Equals(object obj)
        {
            var category = obj as Category;
            return category != null && category.Name.Equals(Name);
        }
    }
}